<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>密码检查工具</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
max-width: 500px;
margin: 50px auto;
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
h1 {
text-align: center;
color: #333;
}
label {
font-size: 16px;
color: #333;
}
input {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
}
button {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
font-size: 16px;
}
button:hover {
background-color: #45a049;
}
.message {
margin-top: 15px;
padding: 10px;
border-radius: 5px;
text-align: center;
}
.valid {
background-color: #d4edda;
color: #155724;
}
.invalid {
background-color: #f8d7da;
color: #721c24;
}
</style>
</head>
<body>

<div class="container">
<h1>密码检查工具</h1>
<label for="password">请输入密码：</label>
<input type="password" id="password" placeholder="密码应包含大小写字母、数字和特殊字符">
<button onclick="checkPassword()">检查密码</button>
<div id="message" class="message"></div>
</div>

<script>
function checkPassword() {
const password = document.getElementById('password').value;
const messageElement = document.getElementById('message');

// 正则表达式：至少包含一个大写字母、一个小写字母、一个数字和一个特殊字符
const regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+={}\[\]:;"'<>,.?/-]).{8,20}$/;

if (regex.test(password)) {
messageElement.textContent = "密码符合要求！";
messageElement.className = "message valid";
} else {
messageElement.textContent = "密码必须包含：大写字母、小写字母、数字和特殊字符（8-20个字符）。";
messageElement.className = "message invalid";
}
}
</script>

</body>
</html>


